#include <bits/stdc++.h>
#include "../../tools/tools.h"
using namespace std;

constexpr int INF = 0x7fffffff; // 无穷大
typedef long long ll;

class Solution {
public:
    long long maximumTotalCost(vector<int>& nums) {
        const int n = nums.size();
        vector<ll> dp(n, 0);
        if(n == 1) return nums[0];
        dp[0] = nums[0], dp[1] = max(nums[0] - nums[1], nums[0] + nums[1]);
        for (int i = 2; i < n; i++) {
            dp[i] = max(dp[i - 1] + nums[i], dp[i - 2] + nums[i - 1] - nums[i]);
        }
        return dp[n - 1];
    }
};

int main(int argc, const char** argv) {
    Solution s;
    vector d = {-14, -13, -20};
    debug(s.maximumTotalCost(d));
    return 0;
}
